<template>
  <!-- <Scaner :show.sync="show" :formData="formData" /> -->
  <div></div>
</template>

<script>
// import Scaner from '@/components/h5-scan/index.vue'
export default {
  // components: { Scaner },
  props: {
    // 使用后置相机
    useBackCamera: {
      type: Boolean,
      default: true,
    },
    // 扫描识别后停止
    stopOnScaned: {
      type: Boolean,
      default: true,
    },
    drawOnfound: {
      type: Boolean,
      default: true,
    },
    // 线条颜色
    lineColor: {
      type: String,
      default: '#03C03C',
    },
    // 线条宽度
    lineWidth: {
      type: Number,
      default: 2,
    },
    // 视频宽度
    videoWidth: {
      type: Number,
      default: document.documentElement.clientWidth || document.body.clientWidth,
    },
    // 视频高度
    videoHeight: {
      type: Number,
      default: document.documentElement.clientHeight - 48 || document.body.clientHeight - 48,
    },
    responsive: {
      type: Boolean,
      default: false,
    },
    /**
     * formData
     */
    formData: {
      type: Object,
      default: () => ({}),
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      errorMessage: '',
      scanned: '',
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    }
  },
  computed: {},
  watch: {
    show: function (newValue) {
      if (newValue) {
        Object.keys(this.form).forEach((key) => (this.form[key] = ''))
      }
    },
  },
  methods: {
    codeScanned(code) {
      this.scanned = code
      this.$emit('codeScanned', code)
      this.$emit('update:show', false)
    },
    errorCaptured(error) {
      switch (error.name) {
        case 'NotAllowedError':
          this.errorMessage = 'Camera permission denied.'
          break
        case 'NotFoundError':
          this.errorMessage = 'There is no connected camera.'
          break
        case 'NotSupportedError':
          this.errorMessage = 'Seems like this page is served in non-secure context.'
          break
        case 'NotReadableError':
          this.errorMessage = "Couldn't access your camera. Is it already in use?"
          break
        case 'OverconstrainedError':
          this.errorMessage = "Constraints don't match any installed camera."
          break
        default:
          this.errorMessage = 'UNKNOWN ERROR: ' + error.message
      }
      console.error(this.errorMessage)
      alert('相机调用失败')
    },
    getList() {},

    handleSubmit() {
      this.$refs['formRef'].validate((valid) => {
        if (valid) {
        }
      })
    },
    cancel() {
      this.$emit('update:show', false)
    },
  },
  mounted() {
    var str = navigator.userAgent.toLowerCase()
    var ver = str.match(/cpu iphone os (.*?) like mac os/)
    if (ver && ver[1].replace(/_/g, '.') < '10.3.3') {
      alert('相机调用失败')
    }
  },
}
</script>
<style lang="css" scoped>
.scan {
  height: 100%;
  width: 100%;
}
.scan .nav {
  width: 100%;
  height: 48px;
  line-height: 48px;
  position: fixed;
  top: 0;
  left: 0;
}
.scan .nav .title {
  padding: 0;
  margin: 0;
  font-size: 16px;
  color: #ffffff;
}
.scan .nav .close {
  display: inline-block;
  height: 22px;
  width: 22px;
  background-size: auto 100%;
  position: absolute;
  left: 16px;
  top: 14px;
}
</style>
